/**
 * Created by huhai on 17/9/30.
 */
import React from 'react';
import {connect} from 'react-redux';
import ReactLoading from 'react-loading';
import style from './style.scss'
import message from 'antd/lib/message';
import '@@/antd/lib/message/style/css';
import  Actions from '../../actions/globalBase'






 class globalBase extends React.Component{
  constructor(props) {
    super(props)
    this.state = {errorDetail: ''};
  }


   componentWillReceiveProps(nextProps){
    //对比当前的如果error有更新的话，设置state，否则置空state.error
     let error = nextProps.common.errorDetail
     if(error){
       message.error(error)
       this.props.CLEAR_ERRORS()
     }
  }
  componentDidMount(){
    /*显示error提示*/
  }
  render(){
    let common = this.props.common;
    let isFetching = common.isFetching;
    let errorDetail = this.state && this.state.errorDetail;
    errorDetail && console.log('errorDetail', errorDetail)
// console.log(errorDetail)
    return <div className="globalBase">
      {/*是否显示loading*/}
      {isFetching>0?   <ReactLoading type="spokes" color="red" height={40} width={40} className={style.loading}/> : ''}
    </div>
  }
}

let mapStateToProps = (state)=>({common: state.common})
const mapDispatchToProps = Actions

export default  connect(mapStateToProps,mapDispatchToProps)(globalBase)
// export default globalBase